﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Nova_DAL;
using Nova_Common;
using System.Data.Common;

public partial class GroupDisc_PostList : System.Web.UI.Page
{
    DbHelper access = new DbHelper();
    DbCommand cmd = null;
    DataSet ds = null;
    string strSQL = "";
    int i = 0;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

        }
    }

    protected string getSQL()
    {
        if (ddlS.SelectedValue.ToString() == "0")
        {
            //strSQL = "SELECT 'P' AA,TAD.CDT,V01 AS X01,TAD.StockNo FROM TAddStorage_List TAD LEFT JOIN TBill_AddStorage TBA ON TAD.StockNo = TBA.StockNo  where 1=1";
            //if (txtX01.Text != "")
            //{
            //    strSQL = strSQL + " AND V01 like '%" + txtX01.Text + "%'";
            //}
            //if (txtStockNo.Text != "")
            //{
            //    strSQL = strSQL + " AND TAD.StockNo like '%" + this.txtStockNo.Text + "%'";
            //}
            //if (txtDateS.Text != "")
            //{
            //    strSQL = strSQL + " and TAD.CDT>='" + txtDateS.Text + "'";
            //}
            //if (txtDateE.Text != "")
            //{
            //    strSQL = strSQL + " and TAD.CDT<= '" + txtDateE.Text + "'";
            //}

            strSQL = "select 'P' AA,StockNo,CDT from TBill_AddStorage  where 1=1";
            if (txtStockNo.Text != "")
            {
                strSQL = strSQL + " AND StockNo like '%" + this.txtStockNo.Text + "%'";
            }
            if (txtDateS.Text != "")
            {
                strSQL = strSQL + " and CDT>='" + txtDateS.Text + "'";
            }
            if (txtDateE.Text != "")
            {
                strSQL = strSQL + " and CDT<= '" + txtDateE.Text + "'";
            }

        }
        else
        {
            //strSQL = "SELECT 'I' AA,TDS.CDT,W01 AS X01,TDS.StockNo FROM TDelStorage_List TDS LEFT JOIN TBill_DelStorage TBD ON TDS.StockNo = TBD.StockNo where 1=1";
            //if (txtX01.Text != "")
            //{
            //    strSQL = strSQL + " AND W01 like '%" + txtX01.Text + "%'";
            //}
            //if (txtStockNo.Text != "")
            //{
            //    strSQL = strSQL + " AND TDS.StockNo like '%" + this.txtStockNo.Text + "%'";
            //}
            //if (txtDateS.Text != "")
            //{
            //    strSQL = strSQL + " and TDS.CDT>='" + txtDateS.Text + "'";
            //}
            //if (txtDateE.Text != "")
            //{
            //    strSQL = strSQL + " and TDS.CDT<= '" + txtDateE.Text + "'";
            //}
            strSQL = "select 'I' AA,StockNo,CDT from TBill_DelStorage  where 1=1";
            if (txtStockNo.Text != "")
            {
                strSQL = strSQL + " AND StockNo like '%" + this.txtStockNo.Text + "%'";
            }
            if (txtDateS.Text != "")
            {
                strSQL = strSQL + " and CDT>='" + txtDateS.Text + "'";
            }
            if (txtDateE.Text != "")
            {
                strSQL = strSQL + " and CDT<= '" + txtDateE.Text + "'";
            }
        }
        if (cobDueState.SelectedValue != "-1")
        {
            strSQL += " AND Bill_Status = '"+cobDueState.SelectedValue+"'";
        }
        
       
        strSQL = strSQL + " order by CDT";
        return strSQL;
    }

    protected void gvbind()
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();
    }


   
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "parent.window.returnValue='" + e.Row.Cells[1].Text.Trim().Replace("&nbsp;", "") + "," + e.Row.Cells[2].Text.Trim().Replace("&nbsp;", "") + "';parent.window.close();");

            //鼠标移动到每项时颜色交替效果   
            //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
            //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

            //设置悬浮鼠标指针形状为"小手"   
            e.Row.Attributes["style"] = "Cursor:hand";
        }
    }

    protected void ibtnFindPos_Click(object sender, ImageClickEventArgs e)
    {
        lbMsg.Text = "";
        try
        {
            if(txtDateS.Text!=""&&txtDateS.Text!=null)
            {
                DateTime.Parse(txtDateS.Text);
            }
            if (txtDateE.Text != "" && txtDateE.Text != null)
            {
                DateTime.Parse(txtDateE.Text);
            }
            
        }
        catch
        {
            lbMsg.Text = "录入的日期格式不正确";
            return;
        }
        gvbind();
    }

}

